package cn.xenosp.server.module.dict.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.xenosp.server.common.tools.IdUtil;
import cn.xenosp.server.common.tools.ObjectConvert;
import cn.xenosp.server.module.dict.entity.SysDictTypeVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.xenosp.server.module.dict.entity.SysDictType;
import cn.xenosp.server.module.dict.service.SysDictTypeService;
import cn.xenosp.server.module.dict.mapper.SysDictTypeMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author TongHui
* @description 针对表【sys_dict_type(字典类型表)】的数据库操作Service实现
* @createDate 2024-10-20 19:58:45
*/
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType>
    implements SysDictTypeService{

    @Override
    public IPage getPage(SysDictTypeVO sysDictTypeVO) {
        SysDictType dictType = new SysDictType();
        IPage page = new Page(sysDictTypeVO.getPage(), sysDictTypeVO.getLimit());
        ObjectConvert.copyVoToEntity(sysDictTypeVO,dictType);
        return page(page,new LambdaQueryWrapper<SysDictType>()
                .eq(ObjectUtil.isNotEmpty(dictType.getId()),SysDictType::getId,dictType.getId())
                .like(ObjectUtil.isNotEmpty(dictType.getName()),SysDictType::getName,dictType.getName())
                .like(ObjectUtil.isNotEmpty(dictType.getType()),SysDictType::getType,dictType.getType())
                .eq(ObjectUtil.isNotEmpty(dictType.getStatus()),SysDictType::getStatus,dictType.getStatus())
        );
    }

    @Override
    public void update(SysDictTypeVO sysDictTypeVO) {
        SysDictType dictType = new SysDictType();
        ObjectConvert.copyVoToEntity(sysDictTypeVO,dictType);
        updateById(dictType);
    }

    @Override
    public void save(SysDictTypeVO sysDictTypeVO) {
        SysDictType dictType = new SysDictType();
        ObjectConvert.copyVoToEntity(sysDictTypeVO,dictType);
        dictType.setId(IdUtil.getId());
        save(dictType);
    }

    @Override
    public void delete(SysDictTypeVO sysDictTypeVO) {
        SysDictType dictType = new SysDictType();
        ObjectConvert.copyVoToEntity(sysDictTypeVO,dictType);
        removeById(dictType);
    }
}




